#include "screen.h"

struct trap_frame
{
     unsigned long ds, es, gs, fs;
     unsigned long edi, esi, ebp, _esp, ebx, edx, ecx, eax;
     unsigned long int_no, err_code;
     unsigned long eip, cs, eflags, esp, ss;
} __attribute__((packed));

void int_default(struct trap_frame* tf);
typedef void (*int_handler)(struct trap_frame*);

int_handler handlers[256] = {int_default};

static char* trap_msg[] = {
     "Divide Error",
     "Debug Exceptions",
     "Intel reserved",
     "Breakpoint",
     "Overflow",
     "Bounds Check",
     "Invalid Opcode",
     "Coprocessor Not Available",
     "Double Fault",
     "Coprocessor Segment Overrun",
     "Invalid TSS",
     "Segment Not Present",
     "Stack Exception",
     "General Protection",
     "Page Fault",
     "Intel reserved",
     "Coprocessor Error",
};

void handler_init()
{
     int i;
     for (i = 0; i < 256; ++i)
     {
	  handlers[i] = int_default;
     }
}

static inline void dump_tf(struct trap_frame* tf)
{

     
}


void handler_dispatcher(struct trap_frame* tf)
{
     int_handler int_func = handlers[tf->int_no];
     int_func(tf);
}

/* default handler */
void int_default(struct trap_frame* tf)
{
     puts("TRAP ");
     disp_int(tf->int_no);
     puts(trap_msg[tf->int_no]);
     
     dump_tf(tf);     
     return;
}


